package com.weiwu.weiwustore.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.weiwu.weiwustore.entity.Material;
import com.weiwu.weiwustore.pojo.MaterialItemVo;
import com.weiwu.weiwustore.pojo.MaterialListVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 材料
 */
@Repository
@Mapper
public interface MaterialMapper extends BaseMapper<Material> {

    @Select(
            "<script>" +
                    "SELECT m.id,mt.tname,mt.introduce,m.mname,s.sname,m.quantity,m.price,m.updatetime FROM `material` m JOIN material_type mt ON m.typeid = mt.id JOIN store s ON m.storeid = s.id " +
                    "<where>" +
                    "      m.del = 0 " +
                    "      <if test=\"select != null and select != '' \">" +
                    "           and (m.mname like concat('%',#{select},'%') or mt.tname like concat('%',#{select},'%'))" +
                    "      </if> " +
                    "      <if test=\"storeid != null and storeid != '' \">" +
                    "           and m.storeid = #{storeid} " +
                    "      </if> " +
                    "      <if test=\"begin != null and size != null\">" +
                    "        limit #{begin}, #{size}" +
                    "      </if> " +
                    "</where>" +
                    "</script>"
    )
    List<MaterialListVo> selectListBymap(@Param("begin") Integer begin,@Param("size") Integer size,
                                         @Param("storeid") String storeid, @Param("select") String select);


    @Select(
            "<script>" +
                    "SELECT m.mname,m.id,mt.tname FROM `material` m,material_type mt"+
            "<where>" +
                    "m.typeid = mt.id and m.storeid = #{storeid}"+
            "</where>" +
            "</script>"
    )
    List<MaterialItemVo> selectItemBystoreid(@Param("storeid") String storeid);
}
